﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace SDATA
{
    public class DFORMAT
    {
        public static DataTable NumberFormat(ref DataTable dt, string[] colArr, char c)
        {
            DataTable dtCloned = dt.Clone();            
            if (dt!=null&&colArr!=null){
                if(dt.Rows.Count>0 && dt.Columns.Count>0 && colArr.Count()>0)
                {
                    //CHANGE TYPE COLUMN
                    foreach (string col in colArr)
                        dtCloned.Columns[col].DataType = typeof(String);
                    //FILL DATA
                    foreach (DataRow row in dt.Rows)
                    {
                        dtCloned.ImportRow(row);
                    }
                    //FORMAT
                    for (int i = 0; i < dtCloned.Rows.Count; i++)
                    {
                        foreach (string col in colArr)
                        {
                            dtCloned.Rows[i][col] = string.Format("{0:0,0}", double.Parse(dtCloned.Rows[i][col].ToString())).Replace(',', c);
                            if (dtCloned.Rows[i][col].ToString() == "00")
                                dtCloned.Rows[i][col] = "0";
                        }                            
                    }
                }
            }
            dt = dtCloned;
            return dtCloned;
        }
        
    }
}
